package common.page;

import common.extremecomponents.ExtremeTablePage;
import common.extremecomponents.ExtremeTablePageRequestFactory;
import org.extremecomponents.table.limit.Limit;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: Liu_jc
 * Date: 13-8-30
 * Time: 上午10:40
 * To change this template use File | Settings | File Templates.
 */
public class PageRequestFactory {

    static int DEFAULT_PAGE_SIZE = 10;
    static int MAX_PAGE_SIZE = 500;

    static{
        System.out.println("PageRequestFactory.DEFAULT_PAGE_SIZE="+DEFAULT_PAGE_SIZE);
        System.out.println("PageRequestFactory.MAX_PAGE_SIZE="+MAX_PAGE_SIZE);
    }

    public static <T> PageRequest<T> bindPageRequest(PageRequest pr,HttpServletRequest request,String defaultSortColumns){
        return  bindPageRequest(pr,request,defaultSortColumns,DEFAULT_PAGE_SIZE);
    }

    public static PageRequest bindPageRequest(PageRequest pr,HttpServletRequest request,String defaultSortColumns,int defaultPageSize){
        Limit limit = ExtremeTablePage.getLimit(request, defaultPageSize);
        ExtremeTablePageRequestFactory.bindPageRequest(pr, limit, defaultSortColumns);
        if(pr.getPageSize() > MAX_PAGE_SIZE) {
            pr.setPageSize(MAX_PAGE_SIZE);
        }
        return pr;
    }

}
